<?php
include_once('../class/DBHelper.class.php');

class HomeModel extends DBHelper {

    public function insertVova($params) {
        if (count($params) < 1) {
            return false;
        }

        $holder = $this->holderInsert($params);
        $sql = "INSERT INTO `t_vova` (`title`, `content`, `character`) VALUES ($holder)";
        $result = $this->execSQL($sql, $params, true);
        return $result;
    }

    public function listVova($start, $limit, $strSeach = '') {
        $sql = "select id, title from `t_vova`";
        $params = array();
        $where = "";
        if ($strSeach != '') {
            $where = " where title like ?";
            $params = array('s', '%'. $strSeach .'%');
        }

        $sql .= $where." order by id desc limit ".$start ."," .$limit;
        $list = $this->execSQL($sql, $params, false);

        return $list;
    }

    public function countVova($strSeach = '') {
        $params = array();
        $where = "";
        if ($strSeach != '') {
            $where = " where title like ?";
            $params = array('s', '%'. $strSeach .'%');
        }

        $sqlCount = "SELECT count(id) as count FROM `t_vova` " . $where;
        $resultTotal = $this->execSQL($sqlCount, $params, false);
        $total = $resultTotal[0]['count'];

        return $total;
    }

    public function getVovaById($id) {
        if (!is_numeric($id)) {
            return null;
        }
        $sql = "select * from `t_vova` where id = ?";
        $result = $this->execSQL($sql, array('i', $id), false);
        return $result;
    }

    public function delete($id) {
        if (!is_numeric($id)) {
            return null;
        }
        $sql = "delete from `t_vova` where id = ?";
        $result = $this->execSQL($sql, array('i', $id), true);
        return $result;
    }

    public function editVova($params) {
        if (count($params) < 1) {
            return false;
        }

        $sql = "UPDATE `t_vova` SET `title` = ? , `content` = ?, `character` =? WHERE id = ?";
        $result = $this->execSQL($sql, $params, true);
        return $result;
    }

}
?>